const { sequelize, DataTypes } = require('../utill/getSequelize')


//具体题目内容
// const T_exam_content = sequelize.define('T_exam_content', {
// });


//题目表
const T_exam_question = sequelize.define('T_exam_question', {
    id: {
        type: DataTypes.INTEGER,
        primaryKey: true,
        autoIncrement: true,
    },

    //(外键)   课程中的id为主键
    sub_id: {
        type: DataTypes.INTEGER,
        allowNull: true
    },

    label: {
        type: DataTypes.JSON,
        allowNull: true
    },



    // chapter: {
    //     type: DataTypes.INTEGER
    // },


    //以下三个属性组成具体题目

    //题干
    questionContent: {
        type: DataTypes.TEXT,
        allowNull: true
    },

    //选项
    options: {
        type: DataTypes.JSON,
        allowNull: false
    },

    //正确答案
    answer: {
        type: DataTypes.TEXT,
        allowNull: false,
    },
    // //解析
    // parse: {
    //     type: DataTypes.TEXT,
    // },

    type: { //1.单选题 2.多选题 3.判断题 4.填空题 5.简答题
        type: DataTypes.STRING,
        allowNull: false,
    },

    score: {//题目总分(千分制)
        type: DataTypes.INTEGER,
        // allowNull: true,
    },


    difficulty: {//题目难度
        type: DataTypes.STRING,
        allowNull: false,
    },



    // create_user: {//创建人
    //     type: DataTypes.INTEGER,
    //     allowNull: false,
    // },

    // status: {
    //     //1正常
    //     type: DataTypes.INTEGER,
    //     allowNull: false,
    // },

    // deleted: {
    //     type: DataTypes.INTEGER,
    //     allowNull: false,
    // }

});




// const { T_exam_label } = require('./t_exam_label');
const { T_subjects } = require('./t_exam_subjects');

// //让问题的标签关联标签表
// T_exam_question.belongsTo(T_exam_label, {
//     foreignKey: 'label_id',
//     targetKey: 'id'
// });
//让问题对应每一个科目类型
T_exam_question.belongsTo(T_subjects, {
    foreignKey: 'sub_id',
    targetKey: 'id'
});


(async () => {
    try {
        await sequelize.sync({ force: false });
        console.log('All models were synchronized successfully.');
    } catch (error) {
        console.log(error);
    }

})();


module.exports = { T_exam_question };